"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getRect = getRect;

/**
 * 获取 boundingClientRect
 *
 * @param ref 要获取矩形的 DOM Ref
 * @param selector 要获取矩形的 DOM 的选择器，会从 DOM Ref 下查找，不传则获取 ref 的矩形
 *
 * * @example
 * ```tsx
 * useReady(async () => {
 *    const rect = await getRect(ref);
 * });
 * ```
 */
function getRect( // eslint-disable-next-line @typescript-eslint/no-explicit-any
ref, selector) {
  return new Promise(function (resolve, reject) {
    if (!ref.current) {
      reject();
      return;
    }

    if (!selector) {
      resolve([ref.current.getBoundingClientRect()]);
    } else {
      resolve(Array.from(ref.current.querySelectorAll(selector)).map(function (x) {
        return x.getBoundingClientRect();
      }));
    }
  });
}